home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / PixelFlipper src / New cdev messages / cdev class.c next >
Encoding:
C/C++ Source or Header  |  1990-11-09  |  3.7 KB  |  294 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.  *  cdev class.c - standard cdev object
  4.  *
  5.  *  Copyright (c) 1989 Symantec Corporation.  All rights reserved.
  6.  *
  7.  */
  8.  
  9. #include "cdev.h"
  10.  
  11.  
  12. /*
  13.  *  _main - cdev entry point
  14.  *
  15.  *  The correct value for A4 must be in A0 on entry.  When built as
  16.  *  an application (for debugging purposes), "cdev runner" calls this
  17.  *  routine with A0=0; this signals us NOT to try to unload A4-based
  18.  *  segments.  When built as a cdev, "cdev stub" loads A0 with the
  19.  *  address of the cdev before calling this routine.  (Note that this
  20.  *  file MUST be in the same segment as "cdev stub.c".)
  21.  *
  22.  */
  23.  
  24. pascal long
  25. _main(msg, item, nitems, id, event, value, dp)
  26. int msg, item, nitems, id;
  27. EventRecord *event;
  28. cdev *value;
  29. WindowPeek dp;
  30. {
  31.     long result;
  32.     
  33.         /*  set up A4  */
  34.  
  35.     asm {
  36.         move.l    a4,-(sp)
  37.         movea.l    a0,a4
  38.     }
  39.     
  40.         /*  respond to message  */
  41.  
  42.     if (msg == macDev)
  43.         result = Runnable();
  44.     else {
  45.         if (msg == initDev) {
  46.             if (value = New()) {
  47.                 value->dp = dp;
  48.                 value->refnum = dp->windowKind;
  49.                 value->rsrcID = id;
  50.                 value->lastItem = nitems;
  51.             }
  52.         }
  53.         if (result = (long) value) {
  54.             value->event = event;
  55.             result = value->Message(msg, item);
  56.         }
  57.     }
  58.     
  59.         /*  restore A4  */
  60.  
  61.     asm {
  62.         move.l    a4,d0
  63.         beq.s    @1
  64.     }
  65.     UnloadA4Seg(0L);
  66.     asm {
  67. @1        movea.l    (sp)+,a4
  68.     }
  69.     return(result);
  70. }
  71.  
  72.  
  73. /*
  74.  *  cdev::Message - respond to message
  75.  *
  76.  *  The message is dispatched to the appropriate handler.
  77.  *
  78.  *  Few subclasses will need to override this method.
  79.  *
  80.  */
  81.  
  82. long
  83. cdev::Message(msg, item)
  84. int msg, item;
  85. {
  86.     long result;
  87.     
  88.     switch (msg) {
  89.         case initDev:
  90.             Init();
  91.             break;
  92.         case hitDev:
  93.             ItemHit(item - lastItem);
  94.             break;
  95.         case closeDev:
  96.             status = 0;
  97.             break;
  98.         case nulDev:
  99.             Idle();
  100.             break;
  101.         case updateDev:
  102.             Update();
  103.             break;
  104.         case activDev:
  105.             Activate();
  106.             break;
  107.         case deactivDev:
  108.             Deactivate();
  109.             break;
  110.         case keyEvtDev:
  111.             if (!(event->modifiers & cmdKey))
  112.                 Key((unsigned char) event->message);
  113.             else if (event->message != autoKey)
  114.                 CmdKey((unsigned char) event->message);
  115.             break;
  116.         case undoDev:
  117.             Undo();
  118.             break;
  119.         case cutDev:
  120.             Cut();
  121.             break;
  122.         case copyDev:
  123.             Copy();
  124.             break;
  125.         case pasteDev:
  126.             Paste();
  127.             break;
  128.         case clearDev:
  129.             Clear();
  130.             break;
  131.         case cursorDev:
  132.             DoCursor();
  133.             break;
  134.     }
  135.     if ((result = status) != (long) this)
  136.         Close();
  137.     return(result);
  138. }
  139.  
  140.  
  141. /*
  142.  *  cdev::Error - signal error
  143.  *
  144.  *  A typical call might be "Error(cdevResErr)".
  145.  *
  146.  *  Few subclasses will need to override this method.
  147.  *
  148.  */
  149.  
  150. void
  151. cdev::Error(code)
  152. long code;
  153. {
  154.     status = code;
  155. }
  156.  
  157.  
  158. /*
  159.  *  cdev::Init - handle "initDev" message
  160.  *
  161.  *  Subclasses overriding this method should call "inherited::Init()".
  162.  *
  163.  */
  164.  
  165. void
  166. cdev::Init()
  167. {
  168.     status = (long) this;
  169. }
  170.  
  171.  
  172. /*
  173.  *  cdev::Close - handle "closeDev" message
  174.  *
  175.  *  Subclasses overriding this method should call "inherited::Close()".
  176.  *
  177.  */
  178.  
  179. void
  180. cdev::Close()
  181. {
  182.     delete(this);
  183. }
  184.  
  185.  
  186. /*
  187.  *  cdev::CmdKey - process "keyEvtDev" (command key depressed)
  188.  *
  189.  *  Subclasses overriding this method should call "inherited::CmdKey(c)"
  190.  *  if the command key is not recognized.
  191.  *
  192.  */
  193.  
  194. void
  195. cdev::CmdKey(c)
  196. int c;
  197. {
  198.     switch (c) {
  199.         case 'z': case 'Z':
  200.             Undo();
  201.             break;
  202.         case 'x': case 'X':
  203.             Cut();
  204.             break;
  205.         case 'c': case 'C':
  206.             Copy();
  207.             break;
  208.         case 'v': case 'V':
  209.             Paste();
  210.             break;
  211.     }
  212. }
  213.  
  214.  
  215. /*
  216.  *  null methods
  217.  *
  218.  *  The remainder of the methods in this file are stubs.  Subclasses
  219.  *  may choose to implement appropriate behavior.
  220.  *
  221.  */
  222.  
  223. void
  224. cdev::Activate()
  225. {
  226. }
  227.  
  228.  
  229. void
  230. cdev::Update()
  231. {
  232. }
  233.  
  234.  
  235. void
  236. cdev::Idle()
  237. {
  238. }
  239.  
  240.  
  241. void
  242. cdev::ItemHit(item)
  243. int item;
  244. {
  245. }
  246.  
  247.  
  248. void
  249. cdev::Key(c)
  250. int c;
  251. {
  252. }
  253.  
  254.  
  255. void
  256. cdev::Deactivate()
  257. {
  258. }
  259.  
  260.  
  261. void
  262. cdev::Undo()
  263. {
  264. }
  265.  
  266.  
  267. void
  268. cdev::Cut()
  269. {
  270. }
  271.  
  272.  
  273. void
  274. cdev::Copy()
  275. {
  276. }
  277.  
  278.  
  279. void
  280. cdev::Paste()
  281. {
  282. }
  283.  
  284.  
  285. void
  286. cdev::Clear()
  287. {
  288. }
  289.  
  290. void
  291. cdev::DoCursor()
  292. {
  293. }
  294.